

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>多选表单</title>
  {include file="include/top"}
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-app-form-tags" style="padding: 20px 0 0 0;">
  <input type="hidden" name="selected">
  <input type="hidden" name="selectedID">
</div>

{include file="include/js"}
<script>
  layui.config({
    base: '/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index','form'],function () {
    var $=layui.$;
    var form=layui.form;
    var $id = {$id>0?$id:'0'};

    var $path = "{$path!=''?$path:''}"

    $(function (){
      getData()
    })
    function getData(){
      if($path!=''){
        $url="/"+$path+"/"
      }else{
        $url="";
      }
      $.post($url+"selects2",{id:$id},function (res){
        var html=""
        if(res.code == 0 && res.data.length>0){
          html = "<div class=\"layui-form-item\">\n" +
                  "    <label class=\"layui-form-label\">分类</label>\n" +
                  "    <div class=\"layui-input-inline\">\n" +
                  "      <select name=\"yincang\" lay-filter=\"yincang\" lay-search><option value=\"\">请选择</option>";
          for (var i in res.data){
            var d = res.data[i]
            html += "<option value=\""+d.id+"\">"+d.title+"</option>"
          }
          html += "</select>\n" +
                  "    </div>\n" +
                  "  </div>"
        }
        $("#layuiadmin-app-form-tags").append(html)
        layui.form.render();
      })
    }
    $(document).bind("select","select",function (){

    })
    form.on('select(yincang)', function (data) {
      var $id2 = data.value
      var $str = $(this).text()
      if($id2==$id){return false;}
      $id =  $id2
      $("input[name='selected']").val($str)
      $("input[name='selectedID']").val($id)
      $(this).parents(".layui-form-item").nextAll().remove();
      getData()
    });
  });
</script>
</body>
</html>